/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Main;

import gestion_chambes_hotel.Gestion_Chambes_Hotel;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.jdbc.JDBCCategoryDataset;


/**
 *
 * @author anas
 */
public class Main extends javax.swing.JFrame {

    accueil as = new accueil();
    Connection conn=null;
    ResultSet rs=null;
    
    
    public Main() {
        initComponents();
        conn =gestion_chambes_hotel.Gestion_Chambes_Hotel.DB_Connection();
        
        
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        Desktop = new javax.swing.JDesktopPane();
        jLabel7 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(204, 247, 255));
        setMaximumSize(new java.awt.Dimension(1100, 590));
        setMinimumSize(new java.awt.Dimension(1100, 590));
        setPreferredSize(new java.awt.Dimension(1100, 590));
        getContentPane().setLayout(null);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Main/Images/Buttons/Espace_Clienet.png"))); // NOI18N
        jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jLabel1MouseReleased(evt);
            }
        });
        getContentPane().add(jLabel1);
        jLabel1.setBounds(30, 50, 170, 60);

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Main/Images/Buttons/Espace_Reservation.png"))); // NOI18N
        jLabel2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jLabel2MouseReleased(evt);
            }
        });
        getContentPane().add(jLabel2);
        jLabel2.setBounds(30, 130, 170, 60);

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Main/Images/Buttons/Espace_Chercher.png"))); // NOI18N
        jLabel3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jLabel3MouseReleased(evt);
            }
        });
        getContentPane().add(jLabel3);
        jLabel3.setBounds(30, 210, 170, 60);

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Main/Images/Buttons/Espace_Modifier.png"))); // NOI18N
        jLabel4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jLabel4MouseReleased(evt);
            }
        });
        getContentPane().add(jLabel4);
        jLabel4.setBounds(30, 280, 180, 70);

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Main/Images/Buttons/Espace_Supprimer.png"))); // NOI18N
        jLabel5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jLabel5MouseReleased(evt);
            }
        });
        getContentPane().add(jLabel5);
        jLabel5.setBounds(30, 350, 170, 70);

        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Main/Images/Buttons/Espace_Chambre.png"))); // NOI18N
        jLabel6.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jLabel6MouseReleased(evt);
            }
        });
        getContentPane().add(jLabel6);
        jLabel6.setBounds(30, 430, 170, 60);

        Desktop.setBackground(new java.awt.Color(204, 204, 255));
        Desktop.setMaximumSize(new java.awt.Dimension(950, 600));
        Desktop.setMinimumSize(new java.awt.Dimension(950, 600));

        javax.swing.GroupLayout DesktopLayout = new javax.swing.GroupLayout(Desktop);
        Desktop.setLayout(DesktopLayout);
        DesktopLayout.setHorizontalGroup(
            DesktopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 950, Short.MAX_VALUE)
        );
        DesktopLayout.setVerticalGroup(
            DesktopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 600, Short.MAX_VALUE)
        );

        getContentPane().add(Desktop);
        Desktop.setBounds(200, 0, 950, 600);
        getContentPane().add(jLabel7);
        jLabel7.setBounds(0, 1, 0, 0);

        jLabel9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Main/Images/Accueil/wallhaven-19788.jpg"))); // NOI18N
        jLabel9.setText("jLabel9");
        getContentPane().add(jLabel9);
        jLabel9.setBounds(0, 0, 1070, 590);

        jMenuBar1.setBackground(new java.awt.Color(153, 204, 255));

        jMenu1.setText("Fichiers");

        jMenuItem4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Main/Images/Labels/quit.png"))); // NOI18N
        jMenuItem4.setText("Quitter");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem4);

        jMenuBar1.add(jMenu1);

        jMenu3.setBackground(new java.awt.Color(0, 153, 255));
        jMenu3.setText("Outils");

        jMenu2.setBackground(new java.awt.Color(51, 153, 255));
        jMenu2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Main/Images/Labels/progression.png"))); // NOI18N
        jMenu2.setText("Statistiques");

        jMenuItem2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Main/Images/Labels/statistique.png"))); // NOI18N
        jMenuItem2.setText("Progression");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem2);

        jMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Main/Images/Labels/diag.png"))); // NOI18N
        jMenuItem1.setText("Chambres");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem1);

        jMenu3.add(jMenu2);

        jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_U, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Main/Images/Labels/users.png"))); // NOI18N
        jMenuItem3.setText("Utilisateur");
        jMenuItem3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jMenuItem3MouseReleased(evt);
            }
        });
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem3);

        jMenuItem5.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem5.setText("Langue Arabe");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem5);

        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents
    

    
    
    
    private void jLabel1MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel1MouseReleased
        
        
        Client c =new Client();
        c.Visibility();
        Desktop.removeAll();
        Desktop.add(c);
        c.show();
        
    }//GEN-LAST:event_jLabel1MouseReleased

    private void jLabel2MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel2MouseReleased
        
        Reservation rs = new Reservation();
        rs.Visibility();
        Desktop.removeAll();
        Desktop.add(rs);
        rs.show();
    }//GEN-LAST:event_jLabel2MouseReleased

    private void jLabel3MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel3MouseReleased
        
        Chercher ch = new Chercher();
        ch.Visibility();
        Desktop.removeAll();
        Desktop.add(ch);
        ch.show();
        
    }//GEN-LAST:event_jLabel3MouseReleased

    private void jLabel4MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel4MouseReleased
        
        Modifier md = new Modifier();
        md.visibility();
        Desktop.removeAll();
        Desktop.add(md);
        md.show();
    }//GEN-LAST:event_jLabel4MouseReleased

    private void jLabel5MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel5MouseReleased
        
        Supprimer sup = new Supprimer();
        
        Desktop.removeAll();
        Desktop.add(sup);
        sup.show();
    }//GEN-LAST:event_jLabel5MouseReleased

    private void jLabel6MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel6MouseReleased
        
        Chambre ch = new Chambre();
        ch.visiblity();
        
        ch.setVisible(true);
    }//GEN-LAST:event_jLabel6MouseReleased
    
    private void get_stat()
        {
        
             try {
            
            String query="select PRE_JOUR_OCCU,MONTANT_FACTURE from paiement";
            //String query2="select NUMERO_CHAMBRE from chambre";
            
            JDBCCategoryDataset dataset= new JDBCCategoryDataset(Gestion_Chambes_Hotel.DB_Connection(),query);
            
            JFreeChart chart=ChartFactory.createLineChart("Progression", "Dates","Les Revenues",  dataset, PlotOrientation.VERTICAL, false, true, true);
            //JFreeChart chart1=ChartFactory.createLineChart("Progression", query, query2, dataset);
            
            BarRenderer renderer=null;
            CategoryPlot plot=null;
            renderer=new BarRenderer();
            
            ChartFrame frame=new ChartFrame("La progression des reservations",chart);
            frame.setVisible(true);
            frame.setSize(750,700);
              
        } catch (Exception e) {
            
            JOptionPane.showInternalMessageDialog(null, e.getMessage());
        }
     
        
        }
    public void Progression()
    {
    
             try {
            
            
            String sql_util="select * from utilisateur_connecter where ID=?";
				
				PreparedStatement ps_util=conn.prepareStatement(sql_util);
				ps_util.setInt(1, 1);
                                rs=ps_util.executeQuery();
				
				if(rs.next()){
					
					 String user=rs.getString("username");
                                         System.out.print(user);
                                         if(user.equals("admin")||user.equals("ADMIN"))
                                         {
                                         
                                             get_stat();
                                         }
                                         else{
                                         
                                             JOptionPane.showMessageDialog(null, "Vous n'avez pas le droit d'access");
                                         }
                                            
				}
                                else{
                                
                                    JOptionPane.showMessageDialog(null, "Utilisateur non identifier");
                                }
            
        } catch (Exception e) {
             JOptionPane.showMessageDialog(null, "statistique "+e.getMessage());
        }
        
       
    
    
    }
    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        
       
        Progression();
        
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem3MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem3MouseReleased
        Utilisateurs ut =new Utilisateurs();
        ut.setVisible(true);
    }//GEN-LAST:event_jMenuItem3MouseReleased
    
    
    
    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        
         
           Statistiques st= new Statistiques();
           st.Get_Infos();
        
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
        System.exit(0);
    }//GEN-LAST:event_jMenuItem4ActionPerformed

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
        Main_Ar m_a=new Main_Ar();
        m_a.setVisible(true);
        setVisible(false);
    }//GEN-LAST:event_jMenuItem5ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Main().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDesktopPane Desktop;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    // End of variables declaration//GEN-END:variables
}
